package levels
{
	import org.flixel.*;
	import org.flixel.plugin.photonstorm.*;
	
	import enemies.*;
	import interactions.*;
	import items.*;
	import treasures.*;
	
	/**
	 * ...
	 * @author JAC
	 */
	public class Tutorial_4 extends Level
	{
		private static const STARTED:uint = 0;
		private static const SPAWNED:uint = 1;
		private static const SPOTTED:uint = 2;
		
		private var trapdoor:Trapdoor;
		private var brute:Brute;
		private var _state:uint;
		
		override public function create():void
		{
			super.create();
			
			_state = STARTED;
			_checkGameOver = false;
			
			_maze.load(MazeData.tutorial_4);
			Player.spawnAt(13, 15);
			Tracker.lives = 0;
			Tracker.mapScore = 1000;
			Tracker.minScore = 1;
			
			//Animation.finger(_player.getMidpoint());
			
			addEntity(new LootBag(1, 19));
			trapdoor = addEntity(new Trapdoor(23, 15)) as Trapdoor;
			trapdoor.addText("info", "Trapdoor", 80, 2);
			
			gameStart();
		}
		
		override public function update():void
		{
			super.update();
			
			if (_state == STARTED)
			{
				if (!_player.notMoving)
				{
					_state = SPAWNED;
					Animation.intruderWarning();
					brute = addEntity(new Brute(0, 11)) as Brute;
				}
				else
				{
					trapdoor.say("info");
				}
			}
			else if (_state == SPAWNED)
			{
				if (brute.state == Brute.ANGRY)
				{
					_state = SPOTTED;
					Animation.finger(trapdoor.getMidpoint(), 3);
				}
			}
			else if (_state == SPOTTED)
			{
				if (!brute.alive)
				{
					_checkGameOver = true;
				}
				
				if (!_player.exists)
				{
					logGameEnd();
					FlxG.resetState();
				}
			}
		}
	}
}